﻿CREATE TABLE [dbo].[EntityAddress] (

	[Id] [dbo].[Id] NOT NULL IDENTITY(1000000000, 1), 
	
    [EntityId] [dbo].[Id] NOT NULL, 
	
    [AddressType] [dbo].[EnumerationValue] NOT NULL DEFAULT 0, 
	

	[Line1] [dbo].[AddressLine] NOT NULL DEFAULT '', 

	[Line2] [dbo].[AddressLine] NOT NULL DEFAULT '',

	[City] [dbo].[AddressCity] NOT NULL DEFAULT '', 

	[State] [dbo].[AddressState] NOT NULL DEFAULT '', 

	[ZipCode] [dbo].[AddressZipCode] NOT NULL DEFAULT '', 

	[ZipPlus4] [dbo].[AddressZipPlus4] NOT NULL DEFAULT '', 

	[PostalCode] [dbo].[AddressPostalCode] NOT NULL DEFAULT '', 

	[County] [dbo].[AddressCounty] NOT NULL DEFAULT '',


	[EffectiveDate] [dbo].[EffectiveDate] NOT NULL DEFAULT '01/01/0001',

	[TerminationDate] [dbo].[TerminationDate] NOT NULL DEFAULT '12/31/9999',

	[Voided] [dbo].[Voided] NOT NULL DEFAULT 0,

	
    [CreateId] [dbo].[Name] NOT NULL DEFAULT SUSER_NAME () , 

    [CreateDateTime] [dbo].[CreateModifiedDateTime] NOT NULL DEFAULT GETDATE() , 

    [ModifiedId] [dbo].[Name] NOT NULL DEFAULT SUSER_NAME (),

    [ModifiedDateTime] [dbo].[CreateModifiedDateTime] NOT NULL DEFAULT GETDATE(), 

    CONSTRAINT [PK_EntityAddress] PRIMARY KEY ([Id]),
	
    CONSTRAINT [FK_EntityAddress_EntityId] FOREIGN KEY (EntityId) REFERENCES Entity(Id), 

    CONSTRAINT [UNQ_EntityAddress_Segment_Effective] UNIQUE (EntityId, AddressType, EffectiveDate, Voided),

	CONSTRAINT [UNQ_EntityAddress_Segment_Termination] UNIQUE (EntityId, AddressType, TerminationDate, Voided)

)

GO